<?php
/**
 * Created by PhpStorm.
 * User: wangzhen
 * Date: 2018/11/7
 * Time: 上午11:21
 */

 namespace App\Providers;

use GuzzleHttp\Client;
use Illuminate\Support\Facades\Cache;

class SmsSend
{


    public static function sendSms($mobile, $templatecode = 'SMS_63950776')
    {
        $str = random_int(100000,999999);

        $time = time();
        $client = new Client();
        $response = $client->request('POST', 'https://api.mix2.zthysms.com/v2/sendSmsTp', [
            // 如果需要，可以在这里添加请求头、查询参数等
            'headers' => [
                'Accept' => 'application/json',
            ],
            'json' => [
                'username'=>'ebbhy',
                'password'=>md5(md5('307476qiW').$time),
                'tKey' =>$time,
                'signature'=>'【儿宝宝】',
                'tpId'=>'115025',
                'ext'=>'',
                'records'=>[
                    'mobile'=>$mobile,
                    'tpContent'=>[
                        'code'=>$str
                    ],
                ],
            ]
        ]);

        $body = $response->getBody();
        $data = json_decode((string) $body, true); // 将响应体转换为数组

        if ($data['code']==200) {
            Cache::put('vcode'.$mobile,$str,900);
            return true;
        }
    }

}
